package edu.langnan.xiaoli.controller.business;

import edu.langnan.xiaoli.base.AjaxResult;
import edu.langnan.xiaoli.base.controller.BaseController;
import edu.langnan.xiaoli.config.security.TokenService;
import edu.langnan.xiaoli.core.domain.PictureDO;
import edu.langnan.xiaoli.service.FileUploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @author cql
 */
@RestController
@RequestMapping("upload")
public class FileUploadController extends BaseController {

    @Resource(name = "aliyunFileUploadService")
    private FileUploadService fileUploadService;

    @Autowired
    private TokenService tokenService;

    /**
     * 图片上传
     *
     * @param images
     * @return
     */
    @PostMapping(value = "/img", headers = "content-type=multipart/form-data")
    public AjaxResult uploadImage(@RequestParam(value = "images") MultipartFile images) {
        PictureDO result = fileUploadService.uploadImg(images);
        return AjaxResult.success(result);
    }

    /**
     * 移除图片
     *
     * @param pictureDO
     * @return
     */
    @DeleteMapping(value = "/img")
    public AjaxResult deleteImage(@RequestBody PictureDO pictureDO) {
        fileUploadService.deleteImage(pictureDO);
        return AjaxResult.success();
    }


}
